# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=scandir
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}"
         "${MINGW_PACKAGE_PREFIX}-python2-${_realname}")
pkgver=1.5
pkgrel=1
pkgdesc="A better directory iterator and faster os.walk() (mingw-w64)"
url="https://github.com/benhoyt/scandir"
arch=('any')
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
source=("${_realname}-${pkgver}.tar.gz"::https://github.com/benhoyt/scandir/archive/v${pkgver}.tar.gz)
sha256sums=('3b2be74e0be665d22adaf841d1cadab7ed4aa2001a9bb81452e0f498cd0780d8')

prepare() {

  cd ${srcdir}
  cp -r ${_realname}-${pkgver} build-python2-${CARCH}
  cp -r ${_realname}-${pkgver} build-python3-${CARCH}
}

build() {
  cd ${srcdir}/build-python3-${CARCH}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  CPPFLAGS+=" -D_WIN32_WINNT=0x0600" \
    ${MINGW_PREFIX}/bin/python3 setup.py build

  cd ${srcdir}/build-python2-${CARCH}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  CPPFLAGS+=" -D_WIN32_WINNT=0x0600" \
    ${MINGW_PREFIX}/bin/python2 setup.py build
}

package_python3-scandir() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd ${srcdir}/build-python3-${CARCH}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --root=${pkgdir} --prefix=${MINGW_PREFIX} --optimize=1 --skip-build
  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE.txt"
}

package_python2-scandir() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

  cd ${srcdir}/build-python2-${CARCH}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --root=${pkgdir} --prefix=${MINGW_PREFIX} --optimize=1 --skip-build
  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE.txt"
}

package_mingw-w64-i686-python2-scandir() {
  package_python2-scandir
}

package_mingw-w64-i686-python3-scandir() {
  package_python3-scandir
}

package_mingw-w64-x86_64-python2-scandir() {
  package_python2-scandir
}

package_mingw-w64-x86_64-python3-scandir() {
  package_python3-scandir
}
